<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<div class="search-results-heading" onclick="toggleSearchResults('story')">- Story Results</div>

<div class="search-results">
  <div class="sort-by">
    Sort by:
    <s:form id="sortBy" beanclass="org.xptracker.web.SearchActionBean" style="display:inline">
      <s:select name="sortBy" onchange="$('sortDesc').checked = false; $('sortBy').submit()">
        <c:forEach items="relevance,severity,size,owner,creator,createdDate,lastModified,completedDate,dueDate"
                   var="value">
          <s:option>${value}</s:option>
        </c:forEach>
      </s:select>

      <s:checkbox id="sortDesc" name="sortDesc" onchange="$('sortBy').submit()" value="true"
                  disabled="${empty param.sortBy or param.sortBy eq 'relevance'}"/>
      <label for="sortDesc">descending</label>
      <s:hidden name="query" value="${param.query}"/>
    </s:form>
  </div>
  <c:forEach items="${searchBean.searchResults}" var="story">
    <div class="search-result">
      <div class="search-result-summary">
        <xp:story-link story="${story}"/>
      </div>
      <div class="search-result-description">
        <c:choose>
          <c:when test="${empty story.description}">
            (empty)
          </c:when>
          <c:otherwise>
            <xp:wiki-display content="${story.descriptionContent}" maxLines="5"/>
          </c:otherwise>
        </c:choose>
      </div>

      <div class="search-result-details">
        <div class="detail">
          <div class="label">State:</div>
          <xp:search-helper type="state" value="${story.state}"/>
          <c:if test="${!empty story.queue}">(<xp:search-helper type="queue" value="${story.queue.name}"/>)</c:if>
        </div>
        <div class="detail">
          <div class="label">Size/Severity:</div>
          <xp:search-helper type="size" value="${story.size}"/> /
          <xp:search-helper type="severity" value="${story.severity}"/>
        </div>
        <div class="detail">
          <div class="label">Creator:</div>
          <xp:search-helper type="creator" value="${story.creator.username}"/></div>
        <c:if test="${!empty story.owner}">
          <div class="detail">
            <div class="label">Owner:</div>
            <xp:search-helper type="owner" value="${story.owner.username}"/></div>
        </c:if>

        <div class="detail">
          <div class="label">Modified:</div>
          <fmt:formatDate value="${story.lastModified}" pattern="yyyy-MM-dd"/></div>
        <c:if test="${!empty story.dueDate}">
          <div class="detail">
            <div class="label">Due:</div>
            <fmt:formatDate value="${story.dueDate}" pattern="yyyy-MM-dd"/></div>
        </c:if>
        <c:if test="${!empty story.completedDate}">
          <div class="detail">
            <div class="label">Completed:</div>
            <fmt:formatDate value="${story.completedDate}" pattern="yyyy-MM-dd"/></div>
        </c:if>

        <c:if test="${!empty story.customers or !empty story.categories}">
          <div style="clear:both; margin-top: 3px">&nbsp;</div>
        </c:if>

        <c:if test="${!empty story.customers}">
          <div class="customers">
            <div class="label">
              Customers:
            </div>
            <c:forEach items="${story.customers}" var="customer">
              <xp:search-helper type="customers" value="${customer.name}"/>
            </c:forEach>
          </div>
        </c:if>

        <c:if test="${!empty story.categories}">
          <div class="categories">
            <div class="label">
              Categories:
            </div>
            <c:forEach items="${story.categories}" var="category">
              <xp:search-helper type="categories" value="${category.name}"/>
            </c:forEach>
          </div>
        </c:if>
      </div>
      <c:if test="${!empty param.sortBy && param.sortBy ne 'relevance'}">
        <div class="extra-data">
          ${param.sortBy}: ${xp:property(story, param.sortBy)}
        </div>
      </c:if>

      <div style="clear:both"></div>
    </div>
  </c:forEach>
</div>